package jp.ac.aiit.spg.web.todo;

import java.util.List;

import jp.ac.aiit.spg.AbstractSpgPage;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Date;
import java.lang.Integer;

import javax.ejb.EJB;

import org.seasar.teeda.extension.annotation.convert.DateTimeConverter;


import jp.ac.aiit.spg.common.SpgProgressStatus;
import jp.ac.aiit.spg.common.SpgAssignStatus;
import jp.ac.aiit.spg.entity.SpgTask;
import jp.ac.aiit.spg.entity.SpgToDo;
import jp.ac.aiit.spg.service.SpgService;
import jp.ac.aiit.spg.web.login.LoginPage;

import org.seasar.extension.dxo.converter.*;
import org.seasar.extension.dxo.converter.impl.*;

public class TodoAcceptedPage extends AbstractSpgPage {
	
	@EJB
	private SpgService ss;
	private List<SpgTask> tasks = new ArrayList<SpgTask>();
	
	private int todoProgressIndex;
	private List<TodoAcceptedItem> todoAcceptedItems = new ArrayList<TodoAcceptedItem>();
	private String projectName;
	private String wbsNumber;
	private String taskName;
	private int workingTime;
	@DateTimeConverter(pattern = "yyyy/MM/dd")
	private Date startTimePlanned;
	@DateTimeConverter(pattern = "yyyy/MM/dd")
	private Date finishTimePlanned;
	@DateTimeConverter(pattern = "yyyy/MM/dd")
	private Date startTimeActual;
	@DateTimeConverter(pattern = "yyyy/MM/dd")
	private Date finishTimeActual;
	private String taskProgress;
	private Integer taskId;

	public Class initialize() {
		// ログインチェック
		if (this.isLoggedIn() == false) {
			return LoginPage.class;
		}
		return null;
	}

	public Class prerender() {
		todoAcceptedItems.clear();
		String[] sortOrder = {"wbs","startTimePlanned"};
		tasks =ss.listUserTasksByAssignStatus(getLoginUserId(), SpgAssignStatus.ACCEPTED, sortOrder);
		setToDoInfo();
		return null;
	}

	private void setToDoInfo() {
		
		for (SpgTask t : tasks) {
			TodoAcceptedItem item = new TodoAcceptedItem();
			item.setProjectName(t.getWbs().getProject().getName());
			item.setTaskId(t.getId());
			item.setTaskName(t.getName());
			item.setWbsNumber(t.getWbsNumber());
			item.setWorkingTime(t.getWorkingTime());
			item.setStartTimePlanned(t.getStartTimePlanned());
			item.setFinishTimePlanned(t.getFinishTimePlanned());
			item.setStartTimeActual(t.getStartTimeActual());
			item.setFinishTimeActual(t.getFinishTimeActual());
			
			
			item.setTaskProgress(t.getProgress().toString());
			todoAcceptedItems.add(item);
		}
	}


	public Date getFinishTimeActual() {
		return finishTimeActual;
	}

	public void setFinishTimeActual(Date finishTimeActual) {
		this.finishTimeActual = finishTimeActual;
	}

	public Date getStartTimeActual() {
		return startTimeActual;
	}

	public void setStartTimeActual(Date startTimeActual) {
		this.startTimeActual = startTimeActual;
	}
	
	public Date getFinishTimePlanned() {
		return finishTimePlanned;
	}

	public void setFinishTimePlanned(Date finishTimePlanned) {
		this.finishTimePlanned = finishTimePlanned;
	}

	public String getProjectName() {
		return projectName;
	}

	public void setProjectName(String projectName) {
		this.projectName = projectName;
	}

	public Date getStartTimePlanned() {
		return startTimePlanned;
	}

	public void setStartTimePlanned(Date startTimePlanned) {
		this.startTimePlanned = startTimePlanned;
	}

	public Integer getTaskId() {
		return taskId;
	}

	public void setTaskId(Integer taskId) {
		this.taskId = taskId;
	}

	public String getTaskName() {
		return taskName;
	}

	public void setTaskName(String taskName) {
		this.taskName = taskName;
	}

	public String getTaskProgress() {
		return taskProgress;
	}

	public void setTaskProgress(String taskProgress) {
		this.taskProgress = taskProgress;
	}

	public String getWbsNumber() {
		return wbsNumber;
	}

	public void setWbsNumber(String wbsNumber) {
		this.wbsNumber = wbsNumber;
	}

	public int getWorkingTime() {
		return workingTime;
	}

	public void setWorkingTime(int workingTime) {
		this.workingTime = workingTime;
	}

	public void setTodoProgressIndex(int todoProgressIndex){
		this.todoProgressIndex = todoProgressIndex;
	}
	
	public int getTodoProgressIndex(){
		return todoProgressIndex;
	}

	public List<TodoAcceptedItem> getTodoAcceptedItems() {
		return todoAcceptedItems;
	}

	public void setTodoAcceptedItems(List<TodoAcceptedItem> todoAcceptedItems) {
		this.todoAcceptedItems = todoAcceptedItems;
	}

}
